package com.wsc.wisdomchina.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.wsc.wisdomchina.R;
import com.wsc.wisdomchina.Tools.Tools;
import com.wsc.wisdomchina.javaBean.ModuleTabListBean;
import com.wsc.wisdomchina.notice.bean.NoticeListBean;

import java.util.Date;
import java.util.List;

/**
 * 街道特色适配器
 * Created by ${wangtao} on 2017/3/1.
 */

public class ModuleTabDataAdapter extends BaseAdapter {
    private Context context;
    private List<ModuleTabListBean.TabListItem> messageBeen;

    public ModuleTabDataAdapter(Context context, List<ModuleTabListBean.TabListItem> messageBeen) {
        this.context = context;
        this.messageBeen = messageBeen;
    }

    @Override
    public int getCount() {
        return messageBeen.size();
    }

    @Override
    public Object getItem(int position) {
        return messageBeen.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
       ViewHolder holder = null;
        View view = convertView;
        if (view == null) {
            view= LayoutInflater.from(context).inflate(R.layout.item_jdts,null);
            holder = new ViewHolder(view);
            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }

        String guideImage=messageBeen.get(position).getMainImg();
        if(guideImage==null || guideImage.isEmpty())
        {
            holder.item_jdts_image.setVisibility(View.GONE);
        }else {
            holder.item_jdts_image.setVisibility(View.VISIBLE);
            Glide.with(context).load(guideImage).into(holder.item_jdts_image);
        }
        holder.item_jdts_title.setText(messageBeen.get(position).getShowColumn1());
        if(messageBeen.get(position).getShowColumn2()==null || messageBeen.get(position).getShowColumn2().trim().isEmpty())
        {
            holder.item_jdts_content.setText("暂无");
        }else {
            holder.item_jdts_content.setText(messageBeen.get(position).getShowColumn2());
        }
        if(messageBeen.get(position).getShowColumn3()==null || messageBeen.get(position).getShowColumn3().trim().isEmpty())
        {
            holder.item_jdts_address.setText("暂无");
        }else {
            holder.item_jdts_address.setText(messageBeen.get(position).getShowColumn3());
        }
        holder.readCount.setText("" + messageBeen.get(position).getReadCount());
        return view;

    }

    public class ViewHolder {
        private ImageView item_jdts_image;//图片
        private TextView item_jdts_title;//标题
        private TextView item_jdts_content;//内容
        private TextView item_jdts_address;//地址
        private TextView readCount;

        public ViewHolder(View view) {
            item_jdts_image= (ImageView) view.findViewById(R.id.item_jdts_image);
            item_jdts_title= (TextView) view.findViewById(R.id.item_jdts_title);
            item_jdts_content= (TextView) view.findViewById(R.id.item_jdts_content);
            item_jdts_address= (TextView) view.findViewById(R.id.item_jdts_address);
            readCount = (TextView) view.findViewById(R.id.tv_read_count);
        }
    }
}
